﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CrystalDecisions.CrystalReports.Engine;
using System.Data;
using CrystalDecisions.Shared;
using LPV_POS.Module;

    class Mod_khohang
    {

        Mod_baocao baocao;
        public void rpt_baocaokhohang(DataSet dset, ReportDocument rpt, string path_excel, DevExpress.XtraGrid.GridControl luoi_doanhthu)
        {

            try
            {
                cpublic ocpublic = new cpublic();
                Mod_header_report header_report = new Mod_header_report();
                header_report.f_header_report(rpt);

                baocao = new Mod_baocao();

                if (ocpublic.Report_Exist_Object(rpt, "txt_tungaydenngay"))
                {
                    CrystalDecisions.CrystalReports.Engine.TextObject str_thoigian;
                    str_thoigian = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                    if (Variable.str_tungay != "")
                    {
                        str_thoigian.Text = Variable.str_tungay;
                    }
                    else
                    {
                        str_thoigian.Text = "";
                    }
                }
                rpt.SetDataSource(dset.Tables[0]);
                rpt.DataDefinition.FormulaFields["SAN_PHAM"].Text = "{dt_report.SAN_PHAM}" + "";
                rpt.DataDefinition.FormulaFields["TON_KHO_BAN_DAU"].Text = "{dt_report.TON_KHO_BAN_DAU}" + "";
                rpt.DataDefinition.FormulaFields["NHAP_KHO"].Text = "{dt_report.NHAP_KHO}" + "";
                rpt.DataDefinition.FormulaFields["XUAT_KHO"].Text = "{dt_report.XUAT_KHO}" + "";
                rpt.DataDefinition.FormulaFields["NHAP_TRA_LAI"].Text = "{dt_report.NHAP_TRA_LAI}" + "";
                rpt.DataDefinition.FormulaFields["BAN_RA"].Text = "{dt_report.BAN_RA}" + "";
                rpt.DataDefinition.FormulaFields["TON_CUOI_KY"].Text = "{dt_report.TON_CUOI_KY}" + "";
                rpt.DataDefinition.FormulaFields["LUONG_HANG_HOA_THAY_DOI"].Text = "{dt_report.LUONG_HANG_HOA_THAY_DOI}" + "";
            
               
                //xuat file excel
                ExportOptions CrExportOptions;

                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                ExcelFormatOptions CrFormatTypeOptions = new ExcelFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = path_excel;
                CrExportOptions = rpt.ExportOptions;
                CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                CrExportOptions.ExportFormatType = ExportFormatType.Excel;
                CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                CrExportOptions.FormatOptions = CrFormatTypeOptions;
                rpt.Export();

            }
            catch (Exception ex)
            {

                rpt.Dispose();
                //Mod_messagebox mess = new Mod_messagebox();
                //mess.messagebox_pos("Thông báo", "Xuất báo cáo thành file excel không thành công", loaithongbao.canhbao.GetHashCode());
                ////throw;
                luoi_doanhthu.MainView.ExportToExcelOld(path_excel);
            }
            rpt.Dispose();
        }


    }

